home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / BUSINESS / STATA3.LZH / DATAKIT.TUT < prev    next >
Text File  |  1988-08-29  |  8KB  |  248 lines

  1. set output error
  2. set display page 23
  3. set more 1
  4. #delimit ;
  5.  
  6. di _n(13) in wh
  7. "  ___  ____  ____  ____  ____ tm" _n
  8. " /__    /   ____/   /   ____/" _n
  9. "___/   /   /___/   /   /___/    Data.Kit:  Programmed Extensions to Stata" _n
  10. "-------------------------------------------------------------------------"
  11. _n(2) ;
  12.  
  13. di in gr
  14. "Data.Kit is a collection of programs written in Stata that provides some useful"
  15. _n
  16. "data management commands.  Although Data.Kit is written in Stata's programming"
  17. _n
  18. "language, you do not have to know anything about the programming language to"
  19. _n
  20. "use Data.Kit.  We begin by loading the kit:" _n(2) ;
  21.  
  22.  
  23. #delimit cr
  24. mac def path
  25. capture run nullfile.tut
  26. if _rc {
  27.     mac def path "\stata\"
  28.     capture run %path`nullfile.tut
  29.     if _rc {
  30.         mac def path "/usr/stata/"
  31.         capture run %path`nullfile.tut
  32.         if _rc {
  33.             #delimit ;
  34.             di in red
  35. "I cannot find the other tutorial files.  I have looked in the current" _n
  36. "directory and in \stata (DOS) or /usr/stata (Unix).  Is Stata installed" _n
  37. "correctly?" _n(2)
  38. "In any case, I cannot run the tutorial." ;
  39.             #delimit cr
  40.             exit
  41.         }
  42.     }
  43. }
  44. macro define F5 "do %path`contents.tut;"
  45. macro define F6 "do %path`datakit.tut;"
  46.  
  47. drop _all
  48. label drop _all
  49.  
  50. #delimit ;
  51. di in wh ". run %path`Data.Kit" ;
  52. program drop _all ;
  53. run %path`Data.Kit ;
  54. di ; set more 0 ; more ; set more 1 ;
  55.  
  56. di _n(2) in wh
  57. "Overview" _n
  58. "--------" _n ;
  59.  
  60. di in gr
  61. "Data.Kit provides six new commands:" _n(2)
  62. _col(8) in wh "collapse" in gr _col(20)
  63. "make a data set of means, sums, or medians" _n
  64. _col(8) in wh "order" in gr _col(20)
  65. "change the order of the variables in a data set" _n
  66. _col(8) in wh "recast" in gr _col(20) "change the type of a variable" _n
  67. _col(8) in wh "mdytoe" in gr _col(20)
  68. "change month/day/year to elapsed date" _n
  69. _col(8) in wh "etomdy" in gr _col(20)
  70. "change elapsed date into month/day/year" _n
  71. _col(8) in wh "etodow" in gr _col(20)
  72. "calculate day-of-week corresponding to elapsed date" _n ;
  73.  
  74. di in gr
  75. "We will not demonstrate them all here.  At the conclusion of this tutorial,"
  76. _n
  77. "you might type '"
  78. in wh "help Data.Kit" in gr "' to learn more about the commands." ;
  79.  
  80. di _n in gr
  81. "We were forced to omit the "
  82. in wh "order" in gr " command from the demonstration version of" _n
  83. "Data.Kit.  During the process of making its calculations, "
  84. in wh "order" in gr " writes a" _n
  85. "temporary data set, something the demonstration version of Stata cannot do."
  86. _n
  87. "If you attempt to use "
  88. in wh "order" in gr ", you will get the message '" in ye "not available in" _n
  89. "demonstration version" in gr "'."  _n(2)
  90. "If you are using the Unix version of Stata in demonstration mode, do not use"
  91. _n
  92. "the " in wh "order" in gr
  93. " command.  Your version of Data.Kit contains the real " in wh "order"
  94. in gr " program," _n
  95. "but it will not work in demonstration mode." ;
  96. set more 0 ; more ; set more 1 ;
  97.  
  98.  
  99. di _n(9) in wh _dup(79) "-" _n in gr
  100. "Data.Kit's " in wh "collapse" in gr
  101. " command converts the data in memory into a data set of" _n
  102. "means or medians or sums.  To illustrate this, we'll use our Census data:" _n
  103. in wh _dup(79) "-" _n(2)
  104. ". use %path`census.dta" ;
  105. noisily use %path`census.dta ;
  106. di _n in wh ". gen mrgrate = marriage/pop18p" ;
  107. gen mrgrate = marriage/pop18p ;
  108. di _n in wh ". gen dvcrate = divorce/pop18p" ;
  109. gen dvcrate = divorce/pop18p ;
  110. label var mrgrate "Marriage rate" ;
  111. label var dvcrate "Divorce rate" ;
  112. di _n in wh ". keep state region mrgrate dvcrate" ;
  113. keep state region mrgrate dvcrate ;
  114. di _n in wh ". describe" ;
  115. set more 0 ; more ; set more 1 ;
  116. noisily describe ;
  117. di _n in wh ". list in 1/8" ;
  118. noisily list in 1/8 ;
  119. set more 0 ; more ; set more 1 ;
  120.  
  121. di _n(3) in wh _dup(79) "-" _n in gr
  122. "If all we wanted was to see the means by region, we would not need Data.Kit."
  123. _n
  124. "Stata's built-in "
  125. in wh "summarize" in gr " command combined with Stata's "
  126. in wh "by" in gr " prefix is all we"
  127. _n
  128. "need:" _n
  129. in wh _dup(79) "-" _n(2)
  130. ". sort region" ;
  131. sort region ;
  132. format mrgrate dvcrate %8.5f ;
  133. di _n in wh
  134. ". by region: summarize mrgrate dvcrate" ;
  135. set more 0 ; more ; set more 1 ;
  136. noisily by region: summarize mrgrate dvcrate ;
  137. set more 0 ; more ; set more 1 ;
  138.  
  139. di _n(2) in wh _dup(79) "-" _n in gr
  140. "We, however, want to make a data set of means:" _n
  141. in wh _dup(79) "-" _n(2)
  142. ". collapse mrgrate dvcrate, by(region) means" ;
  143. noisily collapse mrgrate dvcrate, by(region) nowarning means ;
  144. di _n in wh ". list" ;
  145. noisily list ;
  146. di ; set more 0 ; more ; set more 1 ;
  147.  
  148. di _n(6) in wh _dup(79) "-" _n
  149. "mdytoe" in gr ", " in wh "etomdy" in gr ", and " in wh "etodow" in gr
  150. " are three date manipulation commands.  " in wh "mdytoe" in gr " con-"
  151. _n
  152. "verts a date in month/day/year format into an elapsed date, defined as the" _n
  153. "number of days from "
  154. in ye "January 1, 1960" in gr ".  " in wh "etomdy"
  155. in gr " converts an elapsed date back to" _n
  156. "month/day/year format and "
  157. in wh "etodow" in gr " derives the day-of-week (Sunday, Monday, Tues-" _n
  158. "day, etc.) from an elapsed date.  The syntax of the commands is:" _n ;
  159.  
  160. di _col(8) in wh "mdytoe " in gr "monthvar dayvar yearvar"
  161. in wh ", generate(" in gr "elapvar" in wh ")" _n(2)
  162. _col(8) "etomdy " in gr "elapvar" in wh ", generate("
  163. in gr "monthvar dayvar yearvar" in wh ")" _n(2)
  164. _col(8) "etodow " in gr "elapvar" in wh ", generate("
  165. in gr "dowvar" in wh ")" _n(2) in gr
  166. "This tutorial has silently loaded a data set containing some dates:" _n
  167. in wh _dup(79) "-" _n(4)
  168. ". list" ;
  169. drop _all ;
  170. input str10 event int(month day year) ;
  171. "Stata 1.0" 1 3 1985 ;
  172. "Stata 1.1" 2 1 1985 ;
  173. "Stata 1.2" 7 29 1985 ;
  174. "Stata 1.3" 9 23 1985 ;
  175. "Stata 1.4" 5 29 1986 ;
  176. "Stata 1.5" 4 17 1987 ;
  177. "Stata 2.0" 8 31 1988;
  178. end ;
  179. set more 0 ; more ; set more 1 ;
  180. noisily list ;
  181. di _n(3) in wh _dup(79) "-" _n in gr
  182. "We can use " in wh "mdytoe" in gr" to create an elapsed-date variable:" _n
  183. in wh _dup(79) "-" _n(3)
  184. ". mdytoe month day year, gen(elapsed)";
  185. mdytoe month day year, gen(elapsed) ;
  186. di _n in wh ". list" ;
  187. set more 0 ; more ; set more 1 ;
  188. noisily list ;
  189. di _n(2) in wh _dup(79) "-" _n in gr
  190. "We see that there are "
  191. in ye "9,134" in gr " days between January 1, 1960 and the release of" _n
  192. "the first version of Stata.  There are "
  193. in ye "10,470" in gr " days until the release of Stata"
  194. _n
  195. "2.0.  Elapsed dates are more convenient than month/day/year format because you"
  196. _n
  197. "can subtract them.  There are, for instance, "
  198. in ye "10,470" in gr " - " in ye "9,134" in gr " = " in ye "1,336"
  199. in gr " days be-" _n
  200. "tween the release of Stata 1.0 and Stata 2.0." _n
  201. in wh _dup(79) "-" _n ;
  202. set more 0 ; more ; set more 1 ;
  203.  
  204. di _n(2) in wh _dup(79) "-" _n in gr
  205. "Once we have the elapsed dates, there is no reason to keep the month/day/year"
  206. _n
  207. "dates.  We can always get them back using " in wh "etomdy" in gr ":" _n
  208. in wh _dup(79) "-" _n(4)
  209. ". drop month day year" _n(2)
  210. ". etomdy elapsed, generate(mo da yr)" ;
  211. drop month day year ;
  212. etomdy elapsed, generate(mo da yr) ;
  213. di _n in wh ". list" ;
  214. set more 0 ; more ; set more 1 ;
  215. noisily list ;
  216. di _n(2) in wh _dup(79) "-" _n in gr
  217. "The " in wh "etodow" in gr
  218. " command will derive the day-of-week from an elapsed date:" _n
  219. in wh _dup(79) "-" _n(2)
  220. ". etodow elapsed, generate(wkday)" ;
  221. etodow elapsed, generate(wkday) ;
  222. di _n in wh ". list" ;
  223. set more 0 ; more ; set more 1 ;
  224. noisily list ;
  225. di _n(6) ;
  226. drop _all ;
  227. label drop _all ;
  228. macro define F6 "do %path`qckit.tut;" ;
  229. set more 0 ; more ; set more 1 ;
  230.  
  231. di _n(4) in white
  232. "Demonstration ends" _n
  233. "------------------" _n ;
  234.  
  235.  
  236. di in green
  237. "That concludes our short demonstration, but there's much more.  We now return"
  238. _n
  239. "control to you.  Some suggestions:" _n ;
  240.  
  241. di in green
  242. "If you ..." _col(34) "Then we will show you ..." _n
  243. "    Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
  244. "    Press " in white "F6" in green _col(38) "the next tutorial, "
  245. in white "qckit.tut" _n ;
  246.  
  247. run %path`tobuy.tut ;
  248.